/**
 * @file        line_parser.ipp
 * @brief       Implements line parsing functionality.
 *
 * @author      Emre Turkay <emreturkay at gmail>
 * @date        Jun.01.2008
 *
 * Copyright Emre Turkay 2009
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file COPYRIGHT or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 */

inline boost::optional<line_parser::result_type>
line_parser::parse(const std::string& line)
{
    result_type result;

    std::string::const_iterator i = line.begin();

    if (*i == '+')
    {
        std::string::const_iterator b = ++i;
        while ((i != line.end()) && (!isspace(*i)))
            ++i;
        result.project = std::string(b, i);
        while (isspace(*i))
            ++i;
    }

    while (*i == '@')
    {
        std::string::const_iterator b = ++i;

        while ((i != line.end()) && (!isspace(*i)))
            ++i;
        result.contexts.insert(std::string(b, i));
        while (isspace(*i))
            ++i;
    }

    if (i == line.end())
        return boost::none;

    result.description = std::string(i, line.end());

    return result;
}
